﻿using Iworld.Author.Model;
using Iworld.basis.Service;
using Iworld.Basis.Help;
using Iworld.Basis.Manager;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace Iworld.Author.Service.Client.Import
{
    /// <summary>
    /// 编辑用户基本信息
    /// </summary>
    [DataContract]
    public class EditAuthorBaseInfoImport : CheckAuthorImportBase, IPackageForUpdateModel<IModelToDbContextOfAuthor, Iworld.Author.Model.Author>
    {
        /// <summary>
        /// 存储指针
        /// </summary>
        public int Id
        {
            get
            {
                if (this.Self == null) { return 0; }
                return this.Self.Id;
            }
        }

        /// <summary>
        /// 用户名
        /// </summary>
        [DataMember]
        public string Username { get; set; }

        /// <summary>
        /// QQ号码
        /// </summary>
        [DataMember]
        public string QQ { set; get; }

        /// <summary>
        /// 电话号码
        /// </summary>
        [DataMember]
        public string Phone { set; get; }

        /// <summary>
        /// 二级密码
        /// </summary>
        [DataMember]
        public string TwoLevelPassword { get; set; }


        public void CheckData(IModelToDbContextOfAuthor db)
        {
            if (this.Self.TwoLevelPassword != EncryptHelper.EncryptByMd5(this.TwoLevelPassword))
            {
                throw new Exception("修改用户信息失败,二级密码不正确");
            }
        }

        public void Update(Model.Author model)
        {
            model.QQ = this.QQ;
            model.Username = this.Username;
            model.Phone = this.Phone;
        }
    }
}
